#ifndef __AUTOPID_H__
#define __AUTOPID_H__

#ifdef __cplusplus
extern "C" {
#endif


typedef enum BOOL{
    false = 0,
    true = 1,
}bool;

struct AutoPID {
    float _Kp;
    float _Ki;
    float _Kd;
    float _integral;
    float _previousError;
    float _bangOn;
    float _bangOff;
    float *_input; 
    float *_setpoint; 
    float*_output;
    float _outputMin;
    float _outputMax;
    unsigned long _timeStep;
    float _lastStep;
    bool _stopped;
};

struct AutoPIDRelay {
    struct AutoPID ap;
    bool * _relayState;
    unsigned long _pulseWidth;
    unsigned long _lastPulseTime;
    float _pulseValue;
};

void AutoPID_AutoPID(struct AutoPID *ap, float *input, float *setpoint, float *output, float outputMin, float outputMax,
                     float Kp, float Ki, float Kd);
void AutoPID_run(struct AutoPID *ap);
void AutoPID_setGains(struct AutoPID *ap, float Kp, float Ki, float Kd);
void AutoPID_setBangBang(struct AutoPID *ap, float bangOn, float bangOff);
void AutoPID_setBangBangRange(struct AutoPID *ap, float bangRange);
void AutoPID_stop(struct AutoPID *ap);
void AutoPID_reset(struct AutoPID *ap);
bool AutoPID_isStopped(struct AutoPID *ap);
float AutoPID_getIntegral(struct AutoPID *ap);
void AutoPID_setIntegral(struct AutoPID *ap, float integral);

void AutoPIDRelay_run(struct AutoPIDRelay *apr);
float AutoPIDRelay_getPulseValue(struct AutoPIDRelay *apr);

#ifdef __cplusplus
}
#endif


#endif /* __AUTOPID_H__ */